package ItemBased;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.apache.hadoop.io.Writable;

/*
public class LongPairArrayWritableComparable extends ArrayWritable {

	public LongPairArrayWritableComparable() {
		super(LongPairWritableComparable.class);
	}
	
	public LongPairArrayWritableComparable(LongPairWritableComparable[] values) {
		super(LongPairWritableComparable.class, values);
	}
}
*/


public class LongPairArrayWritableComparable implements Writable {
    public LongPairWritableComparable[] data;

    public LongPairArrayWritableComparable() {

    }

    public LongPairArrayWritableComparable(LongPairWritableComparable[] data) {
        this.data = data;
    }

    public LongPairWritableComparable[] getData() {
        return data;
    }

    public void setData(LongPairWritableComparable[] data) {
        this.data = data;
    }

    public void write(DataOutput out) throws IOException {
        int length = 0;
        if(data != null) {
            length = data.length;
        }

        out.writeInt(length);

        for(int i = 0; i < length; i++) {
            out.writeLong(data[i].getFirst());
            out.writeLong(data[i].getSecond());
        }
    }

    public void readFields(DataInput in) throws IOException {
        int length = in.readInt();

        data = new LongPairWritableComparable[length];

        for(int i = 0; i < length; i++) {
        	long l1 = in.readLong();
        	long l2 = in.readLong();        	
            data[i] = new LongPairWritableComparable(l1,l2);
        }
    }
    
    public static LongPairArrayWritableComparable read(DataInput in) throws IOException{
    	LongPairArrayWritableComparable l = new LongPairArrayWritableComparable();
    	l.readFields(in);
    	return l;
    }
}
